package cn.e4j.modular.api.service;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.modular.api.mapper.UserMapper;
import cn.e4j.modular.crm.entity.GwaaT;
import cn.e4j.modular.system.entity.SysUser;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 用户实现类
 * </p>
 *
 * @author wenchuan.li
 * @since 2019-05-06
 */
@Service
public class UserServiceImpl {

    @Autowired
    UserMapper userMapper;

    @Transactional
    public void checkUser(GwaaT gwaaT, SysUser newUser) {
        //WHERE  gwaaent = #{gwaaent} AND gwaa001 = #{gwaa001}
        UpdateWrapper<GwaaT> wrapper = new UpdateWrapper<>();
        wrapper.eq("GWAAENT",gwaaT.getGWAAENT());
        wrapper.eq("GWAA001",gwaaT.getGWAA001());
        gwaaT.update(wrapper);

        newUser.update(new UpdateWrapper<SysUser>()
                .lambda()
                .eq(SysUser::getACCOUNT, gwaaT.getGWAA001())
        );
    }

    @Transactional(readOnly = true)
    public List<Dto> getGwaaByZcsh() {
        return userMapper.getGwaaByZcsh();
    }

}
